#include "MessageHeader.h"


MessageHeader::MessageHeader()
{
	this->messageLengthInBytes = 0;
	this->type = MessageType::SEND_INFO;
}
MessageHeader::MessageHeader(int messageLengthInBytes,
	MessageType::MessageType type) 
{
	this->messageLengthInBytes = messageLengthInBytes;
	this->type = type;
}
MessageHeader::~MessageHeader()
{

}

void MessageHeader::SetMessageLength(int messageLengthInBytes)
{
	this->messageLengthInBytes = messageLengthInBytes;
}

void MessageHeader::SetMessageType(MessageType::MessageType type)
{
	this->type = type;
}

int MessageHeader::GetMessageLength()
{
	return messageLengthInBytes;
}

MessageType::MessageType MessageHeader::GetMessageType()
{
	return type;
}

string MessageHeader::GetMessageHeaderBuffer()
{

	char buff[5];

	//four bytes for message length including header
	buff[0] = (messageLengthInBytes & 0xFF000000) >> 24;
	buff[1] = (messageLengthInBytes & 0x00FF0000) >> 16;
	buff[2] = (messageLengthInBytes & 0x0000FF00) >> 8;
	buff[3] = (messageLengthInBytes & 0x000000FF);

	//one byte for message type
	buff[4] = (int)this->type;

	string str(buff, 5);

	return str;
}

int MessageHeader::GetMessageHeaderSizeInBytes()
{
	return HEADER_LENGTH;
}

MessageHeader::MessageHeader(const MessageHeader &msg)
{
	this->messageLengthInBytes = msg.messageLengthInBytes;
	this->type = msg.type;
}

